package javacode.chapter05;

public class Example5_5 {
    public static void main(String[] args) {
        // 二维数组
        // 矩阵的转置
        int[][] a = {{2, 5, 0, -1}, {1, 0, -2, 3}};
        int[][] b = new int[4][2];

        // 原矩阵
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }

        // 转置
        for (int i=0;i<a.length;i++){
            for (int j=0;j<a[i].length;j++){
                b[j][i]=a[i][j];
            }
        }

        // 输出转置矩阵
        System.out.println("***********************************");
        for (int i = 0; i < b.length; i++) {
            for (int j = 0; j < b[i].length; j++) {
                System.out.print(b[i][j] + " ");
            }
            System.out.println();
        }

    }
}
